<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>搜索预约车辆</title>
		<meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">
		<link rel="stylesheet" href="../css/bootstrap-3.3.7-dist/css/bootstrap.css">
		<link rel="stylesheet" href="../css/body.css"/>
		<link rel="stylesheet" href="../css/dividePage.css">
		
		<!-- <link rel="stylesheet" type="text/css" href="../css/My97DatePicker/WdatePicker.css"> -->
		<script type="text/javascript" src="../css/My97DatePicker/WdatePicker.js"></script>
		
		<script src="../js/jQuery.js"></script>
		<script src="../css/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
		<script src="../js/index.js"></script>
		<!-- <script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script> -->
		<script src="../js/dividePage.js"></script>
	</head>
	<body>
		<!--首页初始导航条-->
		<nav class="navbar navbar-inverse navbar-fixed-top">
			<div class="container">
				<div class="navbar-header">
					<span class="navbar-brand logo1">川农车辆预约系统</span>
					<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#m1">
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
				</div>
				<div class="navbar-collapse collapse" id="m1">
					<ul class="nav navbar-nav navbar-left">
						<li class="active">
							<a href="../index/index.html"><span class="glyphicon glyphicon-home"></span>&nbsp;首页</a><!--这里的span是设置bootstrap字体图标类-->
						</li>
						
						<!--长期车辆申请菜单-->
						<!--<li class="dropdown">
							<a href="#" class="dropdown-toggle" data-toggle="dropdown">
								长期车辆申请
								<b class="caret"></b>
							</a>
							<ul class="dropdown-menu">
								<li>
									<a href="../index/fileDownload.html">表单下载</a>
								</li>
								<li>
									<a href="../index/longResults.html">结果公示</a>
								</li>
							</ul>
						</li>-->
					</ul>
					
					<ul class="nav navbar-nav navbar-right" id="loginWho">
						<li><a href="../index/login.html">登陆</a></li>
					</ul>
				</div>
			</div>
		</nav>
		
		<!-- 搜索框与显示所有预约结果 -->
		<div class="container" style="margin-top: 10px;">
			<form class="navbar-form navbar-left" id="searchText">
	    		<div class="form-group">
	        		<input type="text" id="carNumber" name="carNumber" class="form-control" placeholder="请输入车牌号">
	    		</div>
	        		<input type="button" value="搜索" class="btn btn-default" onclick="searchCar()" />
	        		<input type="button" value="显示所有记录" class="btn btn-default" onclick="searchAll()" />	
			</form>
		</div>


		<div class="container allStyle">
			<table class="table table-bordered table-striped " id="searchResult">
				<tr>
					<th hidden>Id编号</th>
					<th>车牌号</th>
					<th>申请人姓名</th>
					<th>申请人电话</th>
					<!--<th>申请校区</th>-->
					<th>申请停放时间</th>
					<th>申请理由</th>
					<th>申请结果</th>
					<!-- <th>操作</th> -->
				</tr>
				<!--这个地方会显示回显的后台中的公告数据>-->
				<tbody id="tbody">
        		</tbody>
			</table>
		</div>

		<!--分页-->
		<div class="pageDiv"></div>

	</body>


	<!-- <script type="text/javascript">
		getAllHistory()
		//在搜索以后，通过点击button，回显所有记录
	</script> -->

	<script type="text/javascript">
		//显示所有历史记录
			var data3;
			var tbody1 = "";
			$.ajax({
				type: "GET",
				url: "https://carorder.sicau.edu.cn/adminCar/showOrderHistory",
				beforeSend: function (xhr) {
					xhr.setRequestHeader("token",  sessionStorage.token);
				},
				dataType: "json", //后台返回格式问题
				data:{
					page:1,
					pageSize:10,	
				},
				success: function(data) {
					data3 = data.result
					// console.log(data);
					sessionStorage.allPage = parseInt(data.total/10+1);
					// console.log(data.result);
					//data3 = data3.slice(4);console.log(data3); 
					// data3 = eval('(' + data3 + ')');

					jQuery.each(data3, function(i, value) {
						var trs = "<tr><td hidden>" + value.id + "</td> <td>" +value.plateId+"</td><td>"+ value.name + "</td> <td>" + value.phone + "</td><td>";

						var res_data = value.beginDate + " 至 " + value.endDate;
						
						trs +=  res_data + "</td><td>"+ value.reason;

						//申请结果判断，2：未处理；1：通过；0：拒绝。
						if(value.status == 2){
							trs +=  "</td>" + "<td><font color='black'>未处理</font></td>";
						}
						else if(value.status == 1){
							trs +=  "</td>" + "<td><font color='green'>通过</font></td>";
						}
						else{
							trs +=  "</td>" + "<td><font color='red'>拒绝</font></td>";
						}

						trs = trs  +  "</tr>"

						tbody1 += trs;
					});
					$("#tbody").append(tbody1);
					$(".pageDiv").createPage({
						pageNum: sessionStorage.allPage,
						current: 1,
						backfun: function(e) {
							//console.log(e);//回调
						}
					});
				},
				error: function(data) {
					alert("接收失败,code:" + data.status);
				}
			});

			


			function changePage(e){
				console.log(nowPage);
				console.log(e.getAttribute("value"));
				nowPage = e.getAttribute("value");
				$("#tbody").empty();
				var data3;
				var tbody1 = "";
						$.ajax({
							type: "GET",
							url: "https://carorder.sicau.edu.cn/adminCar/showOrderHistory",
							beforeSend: function (xhr) {
								xhr.setRequestHeader("token", sessionStorage.token);
							},
							dataType: "json", //后台返回格式问题
							data:{
								page:nowPage,
								pageSize:10,	
							},
							success: function(data) {
								data3 = data.result

								sessionStorage.allPage = parseInt(data.total/10+1);

								jQuery.each(data3, function(i, value) {
									var trs = "<tr><td hidden>" + value.id + "</td> <td>" +value.plateId+"</td><td>"+ value.name + "</td> <td>" + value.phone + "</td><td>";

									var res_data = value.beginDate + " 至 " + value.endDate;
									
									trs +=  res_data + "</td><td>"+ value.reason;

									//申请结果判断，2：未处理；1：通过；0：拒绝。
									if(value.status == 2){
										trs +=  "</td>" + "<td><font color='black'>未处理</font></td>";
									}
									else if(value.status == 1){
										trs +=  "</td>" + "<td><font color='green'>通过</font></td>";
									}
									else{
										trs +=  "</td>" + "<td><font color='red'>拒绝</font></td>";
									}

									trs = trs  +  "</tr>"

									tbody1 += trs;
								});
								$("#tbody").append(tbody1);
							},
							error: function(data) {
								alert("接收失败,code:" + data.status);
							}
								});
				}
				function jumpPage(){
					var searchId = $("#pageNum")
					console.log(searchId[0].value);
					nowPage = searchId[0].value
					// console.log(e.getAttribute("value"));

					var data3;
					var tbody1 = "";
					$("#tbody").empty();
							$.ajax({
								type: "GET",
								url: "https://carorder.sicau.edu.cn/adminCar/showOrderHistory",
								beforeSend: function (xhr) {
									xhr.setRequestHeader("token", sessionStorage.token);
								},
								dataType: "json", //后台返回格式问题
								data:{
									page:searchId[0].value,
									pageSize:10,	
								},
								success: function(data) {
									data3 = data.result
									
									sessionStorage.allPage = parseInt(data.total/10+1);

									jQuery.each(data3, function(i, value) {
										var trs = "<tr><td hidden>" + value.id + "</td> <td>" +value.plateId+"</td><td>"+ value.name + "</td> <td>" + value.phone + "</td><td>";

										var res_data = value.beginDate + " 至 " + value.endDate;
										
										trs +=  res_data + "</td><td>"+ value.reason;

										//申请结果判断，2：未处理；1：通过；0：拒绝。
										if(value.status == 2){
											trs +=  "</td>" + "<td><font color='black'>未处理</font></td>";
										}
										else if(value.status == 1){
											trs +=  "</td>" + "<td><font color='green'>通过</font></td>";
										}
										else{
											trs +=  "</td>" + "<td><font color='red'>拒绝</font></td>";
										}

										trs = trs  +  "</tr>"

										tbody1 += trs;
									});
									$("#tbody").append(tbody1);
								
									// var a = document.getElementById("tbody").getElementsByTagName("tr");
									// //console.log(a.length);

									// var zz =new Array(a.length);
									// console.log(zz); 
									// for(var i=0;i<a.length;i++){ zz[i]=a[i].innerHTML } //div的字符串数组付给zz
									// var pageno=1;               //当前页
									
									// var pagesize=20;            //每页多少条信息
									// if(zz.length%pagesize==0){
									// 	var  pageall = zz.length/pagesize; 
									// }
									// else{
									// 	var  pageall = parseInt(zz.length/pagesize)+1;
									// }       //一共多少页
									// $("#p").text(pageall);      //将pageall的值存放到div中，便于下次使用
									// change(1,pageall,zz);


								},
								error: function(data) {
									alert("接收失败,code:" + data.status);
								}
					});
				}
	</script>

</html>